package hut.lgl.dao;

import hut.lgl.bean.Book;
import hut.lgl.utils.JdbcUtil;

import java.util.List;

public class BookDao extends JdbcUtil<Book> {


    //查看所有图书
    public List<Book> getAallBooks(){
        String sql = "select * from book";
        return getAll(sql,Book.class);
    }

    //修改图书
    public int updateBook(Book book){
        String sql = "update book set bname=?,bprice=?,bauthor=?,bdesc=? where bid=?";
        return update(sql,book.getBname(),book.getBprice(),book.getBauthor(),book.getBdesc(),book.getBid());
    }

    //根据bid删除图书
    public int deleteBook(int bid){
        String sql = "delete from book where bid = ?";
        return update(sql,bid);
    }

    //根据bid查询图书
    public Book getBookById(int bid){
        String sql = "select * from book where bid = ?";
        return getOne(sql,Book.class,bid);
    }

    //增加图书
    public int addBook(Book book){
        String sql = "insert into book(bname,bprice,bauthor,bdesc) value (?,?,?,?)";
        return update(sql,book.getBname(),book.getBprice(),book.getBauthor(),book.getBdesc());
    }
}
